package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sync"
)

var Logs *log.Logger

type SSHProxy struct {
	mu       sync.RWMutex
	AppInfos AppInfo `json:"data"` //registry里面的AppInfo
	Conf     Config
	Token    map[string]string
}

type Config struct {
	mu   sync.RWMutex
	Url  string `json:"url"`
	Port string `json:"port"`
}

//var UrlC string
//var PortC string

func (conf *Config) load(f string) error {
	conf.mu.Lock()
	defer conf.mu.Unlock()
	content, err := ioutil.ReadFile(f)
	if err != nil {
		return err
	}
	err = json.Unmarshal(content, conf)
	if err != nil {
		return err
	}
	//	UrlC = conf.Url
	//	PortC = conf.Port
	return nil
}

func NewSSHProxy() *SSHProxy {
	proxy := &SSHProxy{}
	return proxy
}

func main() {
	logfile, err := os.Create("proxy.log")
	if err != nil {
		fmt.Print(err)
	}
	logger := log.New(logfile, "", log.Ldate|log.Ltime)
	Logs = logger
	defer logfile.Close()
	c := &Config{}
	c.load("conf/reg.json")
	p := NewSSHProxy()
	p.serve()
}
